//
//  HttpTool.swift
//  Weibo_SwiftDemo
//
//  Created by gjh on 2020/12/13.
//

import Foundation
import UIKit

class HttpTool: NSObject {
    
    func requestData(callBack: ()->()) -> Void {
        DispatchQueue.global().async {
            print("正在进行网络请求：\(Thread.current)")
            // 网络请求任务
            let url = URL(string: "https://www.baidu.com")
            URLSession.shared.dataTask(with: url!) { (data, _, error) in
                guard let data = data
                else {
                    print("网络请求失败\(String(describing: error))")
                    return
                }
                guard let html = String(data: data, encoding: .utf8)
                else { return }
                print(html)
            }.resume()
            
            DispatchQueue.main.async {
                print("主线程执行 UI:\(Thread.current)")
            }
        }
        callBack()
    }
    
    func requestData(callBack: (String)->()) -> Void {
        DispatchQueue.global().async {
            print("正在进行网络请求：\(Thread.current)")
        }
        callBack("haha")
    }
    
    func requestData(callBack: (String)->(Int)) -> Void {
        DispatchQueue.global().async {
            print("正在进行网络请求：\(Thread.current)")
        }
        _ = callBack("hahaha")
//        return (age)
    }
}
